package com.lifesaftypower.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.lifesaftypower.adapter.ProductSeriesAdapter;
import com.lifesaftypower.product.ProductSeries;

public class ProductSeriesActivity extends Activity {
	public static final String INTENT_SERIES = "INTENT_SERIES";

	private ListView _seriesListView;
	private ProductSeriesAdapter _productSeriesAdapter;
	private ArrayList<ProductSeries> _series;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_product_series);
		Bundle extra = getIntent().getExtras();

		_series = (ArrayList<ProductSeries>) (extra
				.getSerializable(INTENT_SERIES));

		_seriesListView = (ListView) findViewById(R.id.seriesListView);
		_productSeriesAdapter = new ProductSeriesAdapter(this,
				R.layout.series_list_item, _series);

		_seriesListView.setAdapter(_productSeriesAdapter);

		_seriesListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long id) {
				Intent intent = new Intent(ProductSeriesActivity.this,
						ProductActivity.class);

				intent.putExtra(ProductActivity.INTENT_PRODUCT,
						_series.get(position));
				startActivity(intent);
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_product_series, menu);
		return true;
	}

}
